import webapp2
import jinja2
import os
import users
import session

jinja_environment = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))


class MainPage(webapp2.RequestHandler):
    def get(self):
        self.sess = session.Session('kuli879j')
        if self.sess.load():
            texto = "Welcome " + self.sess.user
            template_values = {
                'message': texto,
                'active_user': self.sess.user,
            }
            template = jinja_environment.get_template('index2.html')
            self.response.out.write(template.render(template_values))
        else:
            texto = "Welcome to freetie!"
            template_values = {
                'message': texto,
            }
            template = jinja_environment.get_template('index.html')
            self.response.out.write(template.render(template_values))

app = webapp2.WSGIApplication([('/', MainPage),
                                                ('/signup', users.Register),
                                                ('/login', users.Login),
                                                ('/logout', users.Logout)],
                                                  debug=True)
